package de.gameduell.framework.game.card {
	import fl.transitions.TweenEvent;
	
	import de.gameduell.framework.debug.Debug;
	import de.gameduell.framework.gui.animation.CombinedTween;	

	/**
	 * @author dkum
	 * CombinedTween especially for CardTweens. It adds ALL cards to their target before building the Tween.
	 * That way, modifications in the final position occuring while adding other cards are taken into account.
	 */
	public class CombinedCardTween extends CombinedTween {

		public function CombinedCardTween(aTweenList:Array = null) {
			super(aTweenList);
		}

		override public function start():void {
			_tweenCounter = _tweenList.length;
			if (_tweenCounter == 0) {
				dispatchEvent(new TweenEvent(TweenEvent.MOTION_FINISH, 0, 0));
				Debug.trace("CombinedTween::start: cannot start tweening without tweens! ", Debug.ERROR);
			} else {
				_isPlaying = true;
				for (var i:int = 0;i < _tweenList.length;i++) {
					CardTween(_tweenList[i]).addCardToTarget();
				}
				for (var j:int = 0;j < _tweenList.length;j++) {
					CardTween(_tweenList[j]).buildTween();
				}
				for (var k:int = 0;k < _tweenList.length;k++) {
					var tween:CardTween = _tweenList[k];
					tween.addEventListener(TweenEvent.MOTION_FINISH, onMotionEvent);
					tween.startTweening();
				}
			}
		}
	}
}
